import {getCategoryAPI, getCategoryByIdAPI} from "@/api/layout"
import { getCategoryGoods } from "@/api/detail"

const state = {
    // 分类数据
    category: {},
    categoryData: {},
    categoryDetailData: {},
}
const actions ={
    // 获取分类数据
    async getCategoryData({commit}){
        let res = await getCategoryAPI();
        if(res.status===true){
            commit('GETSUBCATEGORYDATA',res.data);
        }
    },
    //获取分类下的商品数据
    async getCategoryDetailData({commit},id){
        let res = await getCategoryGoods(id);
        if(res.status===true){
            commit('GETDEARILCATEGORYDATA', res.data);
        }
        let res1 = await getCategoryByIdAPI(id);
        if(res1.status===true){
            commit('CATEGORY', res1.data);
        }
    },

}
const mutations ={
    GETSUBCATEGORYDATA(state,categoryData){
        state.categoryData = categoryData
    },
    GETDEARILCATEGORYDATA(state,categoryDetailData) {
        state.categoryDetailData = categoryDetailData
    },
    CATEGORY(state,category) {
        state.category = category
    },
}
const getters = {}

export default {
    namespaced:true,
    state,
    actions,
    mutations,
    getters,
}
